file = open("data/students.txt", mode="r", encoding="utf-8")

# readlines读取所有行
for line in file.readlines():
    # strip 去掉前后空格,换行符，制表符
    print(line.strip())

# 关闭
file.close()

# 简写


with open("data/students.txt", mode="r", encoding="utf-8") as f:
    lines = [line.strip() for line in f.readlines()]
    print(lines)

list = [1, 2, 3, 4, 5, 6, 7, 8]

# w  覆盖  a 追加
with open("data/list.txt", mode="a", encoding="utf-8") as f:
    for i in list:
        f.write(str(i))
        f.write("\n")
